cmake_minimum_required(VERSION 3.8)
project(gene_traj)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

#GDB ros在线调试 
SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
# ros2 run --prefix 'gdb -ex run --args' [package_name] [node_name] 

#set(Eigen3_INCLUDE_DIRS /usr/include/eigen3)

# 查找系统中的依赖项。另外在构建库或执行文件时需要添加这些依赖项。
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(base_interface REQUIRED)
###
find_package(nav_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(visualization_msgs REQUIRED)
# find_package(OsqpEigen REQUIRED)
find_package(message_filters REQUIRED)
find_package(Eigen3)

# 添加非ROS2功能包的依赖项时，需要将其对于的头文件路径在include_directories中写明。
# 而对于依赖项为ROS2功能包时，则无需此操作。
###
# 规定.so/.a库文件路径
link_directories(
  /usr/local/lib       #添加这一行，对代码编译后会在该路径下生成所需的库
)

# 运行时执行所有的cpp
FILE(GLOB SOURCE_LIST "src/*.cpp" 
)


add_executable(gene_traj ${SOURCE_LIST})

# ###
# # 链接osqp文件
# TARGET_LINK_LIBRARIES(gene_traj OsqpEigen::OsqpEigen)

target_include_directories(gene_traj PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>)
target_compile_features(gene_traj PUBLIC c_std_99 cxx_std_17)  # Require C99 and C++17


ament_target_dependencies(
  gene_traj
  "rclcpp"
  "std_msgs"
  "base_interface"
  ###
  "nav_msgs"
  "tf2"
  "tf2_ros"
  "tf2_geometry_msgs"
  "visualization_msgs"
  "geometry_msgs"
  "message_filters"
  # "OsqpEigen"
)

# 安装可执行文件
install(TARGETS gene_traj
  DESTINATION lib/${PROJECT_NAME})

###
# 自己加入，将include文件夹下的头文件安装到install中,include/ 必须加/
install(DIRECTORY include/
  DESTINATION include/
)


if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()


###
# 下面三行，自己加入，---导出相关文件
# 这条语句标记该功能包的头文件位置，以便其他功能包要依赖该功能包时能顺利找到对应的头文件。
ament_export_include_directories(include)
# 一个ros2功能包中可能存在多个库。如果希望其他的功能包能链接到这些库必须使用下面语句声明这些库。
# ament_export_libraries(${library_name})
# ament_export_dependencies会将依赖项导出到下游软件包。
# 这是必需的，这样该库使用者也就不必为那些依赖项调用find_package了。
ament_export_dependencies(${dependencies})

ament_package()
